<template>
	<view class="content">
		<view class="add-img" @click="addImg()">
			<text v-if="tcPhoto==''">+</text>
			<image v-else :src="tcPhoto" mode="widthFix"></image>
		</view>
		<view class="box-add">
			<text>请确认学生编号</text>
			<input class="uni-input" type="text" v-model="num" placeholder="请输入衣服编号">
		</view>
		<button @click="saveBtn">确定保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num:'',
				formData:{
					queueid: '',
					studentid: '',
					number: '',
					tcnameid: '',
				},
				tcPhoto:''
			}
		},
		onLoad(options) {
			this.formData.studentid=options.id
			this.formData.tcnameid=options.tcnameid
			this.formData.queueid=options.queueid
		},
		methods: {
			addImg(){
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: [['original', 'compressed']], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'],
					success: function (res) {
						const tempFilePaths = res.tempFilePaths;
						that.tcPhoto = tempFilePaths[0]
						// console.log(tempFilePaths);
					}
				});
			},
			async saveBtn(){
				if(this.tcPhoto==''){
					this.toast('请上传照片')
					return
				}
				if(this.num==''){
					this.toast('请输入编号')
					return
				}else{
					this.formData.number = this.num
				}
				// this.formData.tcPhoto = this.tcPhoto
				console.log(this.tcPhoto)
				uni.uploadFile({
					url: 'http://116.62.40.75:8080/tc/tcOperate/addTcqueueStudent', //仅为示例，非真实的接口地址
					filePath: this.tcPhoto,
					header: {
						Authorization: uni.getStorageSync("token")
					},
					name: 'tcPhoto',
					formData: this.formData,
					success: (res) => {
						console.log(res);
						if(JSON.parse(res.data).code==200){
							setTimeout(()=>{
								uni.navigateBack(1)
							},1000)
						}
						this.toast(JSON.parse(res.data).msg)
						
					}
				});
			}
		}
	}
</script>

<style lang="less">
	.add-img{
		width: 100%;
		height: 800upx;
		background: #F0F0F0;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 80upx;
		overflow: hidden;
	}
	.box-add{
		width: 100%;
		margin: 40upx 0;
		text{
			font-size: 28upx;
			color: #333;
			display: block;
			margin-bottom: 10upx;
		}
	}
	.uni-input{
		width: 100%;
		height: 80upx;
		background-color: #F0F0F0;
		padding: 0 20upx;
		box-sizing: border-box;
		font-size: 28upx;
		border-radius: 12upx;
	}
	button{
		border-radius: 120upx;
		background: linear-gradient(0deg, #5EA9FA 0%, #7CB6F5 100%);
		color: #fff;
		font-size: 32upx;
		margin: 40upx 0;
	}
</style>